package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Item;

public class ItemDAOImpl extends BaseHibernateDAOImpl<Item> implements ItemDAO {

	public Item getItemByItemID(String itemID) {
		Item item;
		try {
			item = (Item) getSession().get(Item.class, itemID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return item;
	}

	@SuppressWarnings("unchecked")
	public List<Item> getAllWaitingItem() {
		List<Item> items;
		try {
			Query query = getSession().getNamedQuery("AllWaitingItemQuery");
			items = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return items;
	}
	
	@SuppressWarnings("unchecked")
	public List<Item> getAllAccomplishItem() {
		List<Item> items;
		try {
			Query query = getSession().getNamedQuery("AllAccomplishItemQuery");
			items = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return items;
	}

	@SuppressWarnings("unchecked")
	public List<Item> getAllAccomplishItemByPage(int currentPage, int lineSize) {
		List<Item> items;
		try {
			Query query = getSession().getNamedQuery("AllAccomplishItemByPageQuery");
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			items = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return items;
	}

}
